﻿Imports System.Data.OleDb

Public Class DSPhanCongDAO

    Public Function GetTable() As DataTable
        Dim dt As DataTable = New DataTable()
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = "select pc.MaNV, MaBan, HoTen, TenCV from DSPHANCONG pc, NHANVIEN nv, CHUCVU cv where nv.MaNV = pc.MaNV and cv.MaCV = nv.MaCV"
        Dim da As OleDbDataAdapter = New OleDbDataAdapter(str, cn)
        da.Fill(dt)

        cn.Close()
        Return dt
    End Function

    Public Function Insert(ByVal tmp As DSPhanCongDTO) As Integer
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = "insert into DSPHANCONG (MaNV, MaBan) values (@MaNV, @MaBan)"
        Dim cmd As OleDbCommand = New OleDbCommand(str, cn)

        Dim para1, para2 As OleDbParameter
        para1 = New OleDbParameter("@MaNV", tmp.MaNV)
        cmd.Parameters.Add(para1)
        para2 = New OleDbParameter("@MaBan", tmp.MaBan)
        cmd.Parameters.Add(para2)

        Dim result As Integer = cmd.ExecuteNonQuery()
        cn.Close()
        Return result
    End Function

    Public Function Update(ByVal tmp As DSPhanCongDTO) As Integer
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = "update DSPHANCONG set MaNV=@MaNV, MaBan=@MaBan where MaNV=@MaNV and MaBan=@MaBan"
        Dim cmd As OleDbCommand = New OleDbCommand(str, cn)

        Dim para1, para2 As OleDbParameter
        para1 = New OleDbParameter("@MaNV", tmp.MaNV)
        cmd.Parameters.Add(para1)
        para2 = New OleDbParameter("@MaBan", tmp.MaBan)
        cmd.Parameters.Add(para2)

        Dim result As Integer = cmd.ExecuteNonQuery()
        cn.Close()
        Return result
    End Function

    Public Function Delete(ByVal tmp As DSPhanCongDTO) As Integer
        Dim cn As OleDbConnection = DataProvider.ConnectionData()
        Dim str As String = "delete from DSPHANCONG where MaNV=@MaNV and MaBan=@MaBan"
        Dim cmd As OleDbCommand = New OleDbCommand(str, cn)

        Dim para1, para2 As OleDbParameter
        para1 = New OleDbParameter("@MaNV", tmp.MaNV)
        cmd.Parameters.Add(para1)
        para2 = New OleDbParameter("@MaBan", tmp.MaBan)
        cmd.Parameters.Add(para2)

        Dim result As Integer = cmd.ExecuteNonQuery()
        cn.Close()
        Return result
    End Function

End Class
